# 随机生成一个字符串包含数字，大小写字母，可指定生成的长度
# 数字，大小写字符组成的字符串
# 小写字母在大写字母之前，字母在数字之前，奇数在偶数之前
# ascii表 48-57 数字   65-90 大写字母   97-122 小写字母

import random


class Sort:      
    def fn(self,length=20):
        origin = ''
        while length:
            word = random.randint(48,122)
            # 按照这个随机的话，那么有可能会出现 20个一样的字符
            if (word >= 48 and word <= 57) or (word >= 65 and word <= 90) or (word >= 97 and word <= 122):
                origin += chr(word)
                length -= 1
        return origin

    def foo(self,origin):
        odd_number = ''
        even_number = ''
        lowercase = ''
        capital = ''
        target = ''
        for i in origin:
            if ord(i) <= 57:
                if int(i)%2 == 0:
                    even_number += i
                else:
                    odd_number += i
            elif ord(i) >= 97:
                lowercase += i
            else:
                capital += i
        process = sorted(lowercase) + sorted(capital) + sorted(odd_number) + sorted(even_number)
        for i in process:
            target += i
        return target

if __name__ == '__main__':
    a = Sort()
    origin = a.fn()
    print(origin)
    target = a.foo(origin)
    print(target)
